package com.plian.system.wrapper.util;

import com.plian.Tools.StringUtil;
import com.plian.system.cache.*;
import org.mapstruct.Named;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

import static com.plian.system.wrapper.util.WrapperConstant.*;

/**
 * @description:
 * @author: gangan
 * @create: 2022-01-10 19:27
 */
@Component
public class CacheWrapperUtil {

    /**
     * 单个字典code转中文
     * @param dictCode
     * @return
     */
    @Named(DICT_CODE_TO_NAME)
    public String dictCodeToName(String dictCode){
        if (StringUtil.isBlank(dictCode)){
            return null;
        }
        return DictCache.dictCodeToName(dictCode);
    }

    /**
     * 多个字典code转中文
     * @param dictCode
     * @return
     */
    @Named(DICT_CODE_LIST_TO_NAME)
    public String dictCodeListToName(String dictCode){
        if (StringUtil.isBlank(dictCode)){
            return null;
        }
        return DictCache.dictCodeListToName(dictCode);
    }

    /**
     * 多个字典code转中文List
     * @param dictCode
     * @return
     */
    @Named(DICT_CODE_LIST_TO_NAME_LIST)
    public List<String> dictCodeListToNameList(String dictCode){
        if (StringUtil.isBlank(dictCode)){
            return null;
        }
        return DictCache.dictCodeListToNameList(dictCode);
    }

    /**
     * orgId 转name
     * @param orgId
     * @return
     */
    @Named(ORG_ID_TO_NAME)
    public String orgIdToName(String orgId){
        if (StringUtil.isBlank(orgId)){
            return null;
        }
        return OrgCache.orgIdToName(orgId);
    }

    /**
     * orgId 转orgCode
     * @param orgId
     * @return
     */
    @Named(ORG_ID_TO_CODE)
    public String orgIdToCode(String orgId){
        if (StringUtil.isBlank(orgId)){
            return null;
        }
        return OrgCache.orgIdToCode(orgId);
    }

    /**
     * userId 转name
     * @param userId
     * @return
     */
    @Named(USER_ID_TO_NAME)
    public String userIdToName(String userId){
        if(StringUtil.isBlank(userId)){
            return null;
        }
        return UserCache.userIdToName(userId);
    }


    /**
     * 部门id转name
     * @param deptId
     * @return
     */
    @Named(DEPT_ID_TO_NAME)
    public String deptIdToName(Long deptId){
        if (deptId==null){
            return null;
        }
        return DeptCache.deptIdToName(deptId);
    }

    /**
     * 部门id转code
     * @param deptId
     * @return
     */
    @Named(DEPT_ID_TO_CODE)
    public String deptIdToCode(Long deptId){
        if (deptId==null){
            return null;
        }
        return DeptCache.deptIdToCode(deptId);
    }

    /**
     * 部门strid转name
     * @param deptId
     * @return
     */
    @Named(DEPT_STR_ID_TO_NAME)
    public String deptStrIdToName(String deptId){
        if (StringUtil.isBlank(deptId)){
            return null;
        }
        return DeptCache.deptIdToName(Long.valueOf(deptId));
    }

    /**
     * 部门strid转code
     * @param deptId
     * @return
     */
    @Named(DEPT_STR_ID_TO_CODE)
    public String deptStrIdToCode(String deptId){
        if (StringUtil.isBlank(deptId)){
            return null;
        }
        return DeptCache.deptIdToCode(Long.valueOf(deptId));
    }

    /**
     * 部门id转name  如果是企业负责人则返回企业负责人
     * @param deptId
     * @param isLeader
     * @return
     */
    @Named(CHECK_LEADER)
    public String checkLeader(Long deptId, Integer isLeader){
        if (isLeader != null && isLeader == 2){
            return "企业负责人";
        }
        if(deptId == null){
            return null;
        }
        return DeptCache.deptIdToName(deptId);
    }

    /**
     * 员工档案id转name
     * @param staffId
     * @return
     */
    @Named(STAFF_ID_TO_NAME)
    public String staffIdToName(Long staffId){
        if(staffId==null){
            return null;
        }
        return StaffCache.staffIdToName(staffId);
    }

    /**
     * 员工档案id转code
     * @param staffId
     * @return
     */
    @Named(STAFF_ID_TO_CODE)
    public String staffIdToCode(Long staffId){
        if(staffId==null){
            return null;
        }
        return StaffCache.staffIdToCode(staffId);
    }

    /**
     * 产权id转name
     * @param propertyId
     * @return
     */
    @Named(PROPERTY_ID_NAME)
    public String propertyIdToName(String propertyId){
        if(StringUtil.isBlank(propertyId)){
            return null;
        }
        return PropertyCache.propertyIdToName(propertyId);
    }

    /**
     * officeId 转name
     * @param officeId
     * @return
     */
    @Named(OFFICE_ID_TO_NAME)
    public String officeIdToName(Long officeId){
        if (!Optional.ofNullable(officeId).isPresent()){
            return null;
        }
        return OfficeCache.officeIdToName(officeId);
    }
}
